import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)Table of Contents
- 2.1. Loading Prerequisites
- 2.2. Dataset and Preprocessing
- 2.3. Train, Validation, Test Split and Batch Generation
- 2.4. Determining the Benchmark
- 2.5. Model Training and Selection
3. Results and Discussions * 3.1. Results * 3.2. Discussions and Recommendations
In recent years, the global energy industry has changed its focus away from traditional fuel sources, such as oil and coal, to more alternative and sustainable solutions, such as hydroelectric, solar and wind. However, the shift towards renewable energy poses new threats and challenges to existing power grids across the world. One major concern surrounding renewable energy generation is the inherent variability and intermittency of its fuel source, as this can cause disruptions in power grids. Essentially, renewable energy technologies threaten to overwhelm the grid operators.
Renewable energy forecasting, in particular solar generation supply, may provide power grid operators the ability to predict and balance energy generation and consumption. In addition, power grid operators will be able to balance and schedule the distribution of generated power for not only renewable power plants but also conventional (and rigid) power plants, such as coal and natural gas.
import numpy as np
import math
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing import sequence
from tensorflow.keras.models import Sequential
from tensorflow.keras import layers
from tensorflow.keras.optimizers import RMSprop, Adam
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStoppingHere, we will load the already cleaned preprocessed dataset of solar generation per plant per hour. The cleaning was processed outside of this notebook, and followed a framework which follows the industry standard of imputing missing values.
To list a few processes: - using the average between the before(t-1) and after hour(t+1) - using a 1-week average of all similar intervals (ex, if empty during hour 6 of dec 20, take the moving average of all hour 6 from dec 13-dec19) - using a 4-week moving average of that specific hour and day of the week (ex, if empty during hour 6 of dec 20, we take average of hour 6(dec 13, 6, 29, 22)df = pd.read_excel('solar_dataset.xlsx',
sheet_name='metro_manila',
parse_dates=['DATETIME'])df.dtypesDATETIME datetime64[ns]
YEAR int64
MONTH int64
DAY int64
HOUR int64
RESOURCE_ID object
MW float64
Location object
Temperature float64
Dew Point float64
Humidity float64
Wind Speed int64
Wind Gust int64
Pressure float64
Condition object
Location_Name object
dtype: object
df.head(3)| DATETIME | YEAR | MONTH | DAY | HOUR | RESOURCE_ID | MW | Location | Temperature | Dew Point | Humidity | Wind Speed | Wind Gust | Pressure | Condition | Location_Name | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2016-12-26 00:00:00 | 2016 | 12 | 26 | 1 | 2VALSOL_G01 | 0.0 | RPLL | 77.0 | 73.0 | 89.0 | 20 | 31 | 29.6 | Light Rain | NINOY AQUINO INT |
| 1 | 2016-12-26 01:00:00 | 2016 | 12 | 26 | 2 | 2VALSOL_G01 | 0.0 | RPLL | 77.0 | 75.0 | 94.0 | 15 | 0 | 29.6 | Light Rain | NINOY AQUINO INT |
| 2 | 2016-12-26 02:00:00 | 2016 | 12 | 26 | 3 | 2VALSOL_G01 | 0.0 | RPLL | 75.0 | 75.0 | 100.0 | 15 | 0 | 29.6 | Light Rain | NINOY AQUINO INT |
month, day, hour into categorical data, which will be later used in one-hot encoding. In addition, this is the usual preprocessing used in the energy industry here in the Philippines.
df.MONTH = df.MONTH.astype('str')
df.DAY = df.DAY.astype('str')
df.HOUR = df.HOUR.astype('str')df.drop(['Location_Name', 'Location', "YEAR"],axis=1,inplace=True)df with the one-hot encoded dataframe
df = df.join(pd.get_dummies(df[['MONTH','DAY','HOUR','Condition']]))locations = df.RESOURCE_ID.unique()locations[0]'2VALSOL_G01'
df0 = df[df.RESOURCE_ID == locations[0]].copy()df0 = df0.drop(['RESOURCE_ID','DATETIME','MONTH','DAY','HOUR','Condition'],
axis=1)df0 = df0[['Temperature','MW'] + df0.columns[2:].tolist()].copy()df0 = df0.astype('float')DataFrame to be used
df0.head()| Temperature | MW | Dew Point | Humidity | Wind Speed | Wind Gust | Pressure | MONTH_1 | MONTH_10 | MONTH_11 | ... | Condition_Mostly Cloudy / Windy | Condition_Partly Cloudy | Condition_Partly Cloudy / Windy | Condition_Rain | Condition_Rain / Windy | Condition_Rain Shower | Condition_Showers in the Vicinity | Condition_T-Storm | Condition_Thunder | Condition_Thunder in the Vicinity | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 77.0 | 0.0 | 73.0 | 89.0 | 20.0 | 31.0 | 29.6 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 1 | 77.0 | 0.0 | 75.0 | 94.0 | 15.0 | 0.0 | 29.6 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 75.0 | 0.0 | 75.0 | 100.0 | 15.0 | 0.0 | 29.6 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 75.0 | 0.0 | 75.0 | 100.0 | 16.0 | 0.0 | 29.6 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 4 | 77.0 | 0.0 | 77.0 | 100.0 | 13.0 | 0.0 | 29.6 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
5 rows × 99 columns
df0.shape(24021, 99)
plant_capacity = 8.5.8, .1, .1, train-validate-test split was implemented. Since we are dealing with a time-series, the train-validate-test split cannot be randomly selected from the dataset, splitting of dataset should be conducted in a chronogical order. Below we define the starting and ending index for each group
train_validate_test_split = [.8, .1, .1]
train_idx = math.floor(df0.shape[0] * train_validate_test_split[0])
val_idx = math.floor(df0.shape[0] * train_validate_test_split[1]) + train_idxgenerator function below was utilized to yield the appropriate batch. Significant parameters include the lookback, or how far back of the data to consider, delay, or how far into the future are we forecasting, batch_size, refers to the number of training examples utilized in one iteration.
def generator(data, lookback, delay, min_index, max_index, shuffle=False,
batch_size=128, step=1):
if max_index is None:
max_index = len(data) - delay - 1
i = min_index + lookback
while 1:
if shuffle:
rows = np.random.randint(min_index + lookback,
max_index, size=batch_size)
else:
if i + batch_size >= max_index:
i = min_index + lookback
rows = np.arange(i, min(i + batch_size, max_index))
i += len(rows)
samples = np.zeros((len(rows), lookback // step, data.shape[-1]))
targets = np.zeros((len(rows),))
for j, row in enumerate(rows):
indices = range(rows[j] - lookback, rows[j], step)
samples[j] = data[indices]
targets[j] = data[rows[j] + delay][1]
yield samples, targetsfloat_data = df0.values
train_mean = float_data[:train_idx].mean(axis=0)
float_data -= train_mean
train_std = float_data[:train_idx].std(axis=0)
float_data /= train_std
train_mw_std = train_std[1]lookback of either 144 hours (1 week), 288 hours (2 weeks), or 720 hours (1[30-day] month). The initial run was to utilized a 288 hour lookback period due to group’s industry expert’s experience. However, outside consultation with industry experts said 1 week would suffice with this limited dataset.
lookback = 144 # lookback(consider) the previous week data
step = 1 # in hourly granularity
delay = 24 # to forecast the next 24 hours
batch_size = 128train_gen = generator(float_data,
lookback=lookback,
delay=delay,
min_index=0,
max_index=train_idx,
shuffle=True,
step=step,
batch_size=batch_size)
val_gen = generator(float_data,
lookback=lookback,
delay=delay,
min_index=train_idx+1,
max_index=val_idx,
step=step,
batch_size=batch_size)
test_gen = generator(float_data,
lookback=lookback,
delay=delay,
min_index=val_idx,
max_index=None,
step=step,
batch_size=batch_size)
val_steps = (val_idx - (train_idx+1) - lookback)
test_steps = (len(float_data) - (val_idx+1) - lookback)The team used two metrics to establish a baseline error:
(1) the naive method identified in a previous lecture, which we scaled to industry standard
(2) a different framework suggested by industry
def evaluate_naive_method():
batch_maes = []
for step in range(val_steps):
if step % 1000 == 0:
print(step)
samples, targets = next(val_gen)
preds = samples[:, -1, 1]
mae = np.mean(np.abs(preds - targets))
batch_maes.append(mae)
return np.mean(batch_maes)
naive_method = evaluate_naive_method()0
1000
2000
print('NAIVE METHOD 1:', f'{((naive_method * train_mw_std)/plant_capacity):0.2%}') #where 22 is the capacity of the plantNAIVE METHOD 1: 5.84%
benchmark1 = ((naive_method * train_mw_std)/plant_capacity) * 100 For establishing the 2nd baseline error, the team consulted the industry to determine a baseline error. However, even the industry is still conflicted on how to establish a baseline measurement. As of now, the baseline is still being established by policy makers and grid operators.
Luckily, consulting with industry experts gave the team a framework on how to establish a baseline error per plant. The resulting measure looked at the mean squared error of the day-ahead projection(DAP), also called scheduled (Ex-Ante or RTD), and the actual delivered (Ex-Post or RTX).
This was then scaled as a percentage to the capacity of the plant. This was with processed with an industry expert and not included in the notebook. The yielding error resulted with a baseline of12.48%
benchmark2 = 12.48The team utilized 4 models:
- LSTM with 64 nodes
- LSTM with 32 nodes
- Stacked LSTM(2 layer) with 64 and 32 nodes
- Stacked LSTM(2 layer) with 32 and 64 nodes
Dropout of 0.2 and Recurrent Dropout of 0.2 and a RMSProp optimized was implemented for all three.
Epoch=50, with an EarlyStopping of patience=10 and min_delta=0.01 to avoid overfitting and to reduce runtime due to the limited time constraints.
steps_per_epoch_cnt = math.floor(train_idx/batch_size)
val_steps_cnt = round(math.floor((val_idx-train_idx)/batch_size),-1)filepath_lstm64="clark_best_lstm64.hdf5"
cp_lstm64 = ModelCheckpoint(filepath_lstm64, monitor='val_loss', verbose=2, save_best_only=True, mode='min')
es_lstm64 = EarlyStopping(monitor='val_loss', mode='min', verbose=2, patience=10, min_delta=.01)
callbacks_list_lstm64 = [cp_lstm64, es_lstm64]
# fix random seed for reproducibility
seed = 1337
np.random.seed(seed)
model_lstm64 = Sequential()
model_lstm64.add(layers.LSTM(64,
dropout=0.2,
recurrent_dropout=0.2,
input_shape=(None, float_data.shape[-1])))
model_lstm64.add(layers.Dense(64,activation='relu'))
model_lstm64.add(layers.Dense(1))
model_lstm64.compile(optimizer=RMSprop(), loss='mae')
history_lstm64 = model_lstm64.fit_generator(train_gen,
steps_per_epoch=steps_per_epoch_cnt,
epochs=50,
validation_data=val_gen,
validation_steps=val_steps_cnt,
callbacks=callbacks_list_lstm64, verbose=2) WARNING:tensorflow:From /home/ssilva/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /home/ssilva/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/backend.py:4010: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
WARNING:tensorflow:From /home/ssilva/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/50
20/20 [==============================] - 1s 48ms/step - loss: 0.1711
Epoch 00001: val_loss improved from inf to 0.17113, saving model to clark_best_lstm64.hdf5
- 21s - loss: 0.3853 - val_loss: 0.1711
Epoch 2/50
20/20 [==============================] - 1s 42ms/step - loss: 0.1504
Epoch 00002: val_loss improved from 0.17113 to 0.15042, saving model to clark_best_lstm64.hdf5
- 22s - loss: 0.2661 - val_loss: 0.1504
Epoch 3/50
20/20 [==============================] - 1s 41ms/step - loss: 0.1373
Epoch 00003: val_loss improved from 0.15042 to 0.13729, saving model to clark_best_lstm64.hdf5
- 22s - loss: 0.2066 - val_loss: 0.1373
Epoch 4/50
20/20 [==============================] - 1s 40ms/step - loss: 0.1295
Epoch 00004: val_loss improved from 0.13729 to 0.12954, saving model to clark_best_lstm64.hdf5
- 21s - loss: 0.1742 - val_loss: 0.1295
Epoch 5/50
20/20 [==============================] - 1s 50ms/step - loss: 0.1284
Epoch 00005: val_loss improved from 0.12954 to 0.12843, saving model to clark_best_lstm64.hdf5
- 21s - loss: 0.1633 - val_loss: 0.1284
Epoch 6/50
20/20 [==============================] - 1s 47ms/step - loss: 0.1436
Epoch 00006: val_loss did not improve from 0.12843
- 22s - loss: 0.1576 - val_loss: 0.1436
Epoch 7/50
20/20 [==============================] - 1s 45ms/step - loss: 0.1292
Epoch 00007: val_loss did not improve from 0.12843
- 22s - loss: 0.1494 - val_loss: 0.1292
Epoch 8/50
20/20 [==============================] - 1s 49ms/step - loss: 0.1321
Epoch 00008: val_loss did not improve from 0.12843
- 21s - loss: 0.1475 - val_loss: 0.1321
Epoch 9/50
20/20 [==============================] - 1s 40ms/step - loss: 0.1304
Epoch 00009: val_loss did not improve from 0.12843
- 22s - loss: 0.1404 - val_loss: 0.1304
Epoch 10/50
20/20 [==============================] - 1s 43ms/step - loss: 0.1405
Epoch 00010: val_loss did not improve from 0.12843
- 21s - loss: 0.1370 - val_loss: 0.1405
Epoch 11/50
20/20 [==============================] - 1s 42ms/step - loss: 0.1361
Epoch 00011: val_loss did not improve from 0.12843
- 21s - loss: 0.1375 - val_loss: 0.1361
Epoch 12/50
20/20 [==============================] - 1s 41ms/step - loss: 0.1294
Epoch 00012: val_loss did not improve from 0.12843
- 20s - loss: 0.1328 - val_loss: 0.1294
Epoch 13/50
20/20 [==============================] - 1s 42ms/step - loss: 0.1366
Epoch 00013: val_loss did not improve from 0.12843
- 20s - loss: 0.1295 - val_loss: 0.1366
Epoch 00013: early stopping
loss_lstm64 = history_lstm64.history['loss']
val_loss_lstm64 = history_lstm64.history['val_loss']
epochs = range(1, len(loss_lstm64) + 1)
plt.figure()
plt.plot(epochs, loss_lstm64, 'bo', label='Training loss')
plt.plot(epochs, val_loss_lstm64, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
print('Model Error:', f'{((min(val_loss_lstm64) * train_mw_std)/plant_capacity):0.2%}')Model Error: 2.82%
lstm64 = ((min(val_loss_lstm64) * train_mw_std)/plant_capacity) * 100filepath_lstm32="clark_best_lstm32.hdf5"
cp_lstm32 = ModelCheckpoint(filepath_lstm32, monitor='val_loss', verbose=2, save_best_only=True, mode='min')
es_lstm32 = EarlyStopping(monitor='val_loss', mode='min', verbose=2, patience=10, min_delta=.01)
callbacks_list_lstm32 = [cp_lstm32, es_lstm32]
# fix random seed for reproducibility
seed = 1337
np.random.seed(seed)
model_lstm32 = Sequential()
model_lstm32.add(layers.LSTM(32,
dropout=0.2,
recurrent_dropout=0.2,
input_shape=(None, float_data.shape[-1])))
model_lstm32.add(layers.Dense(32, activation='relu'))
model_lstm32.add(layers.Dense(1))
model_lstm32.compile(optimizer=RMSprop(), loss='mae')
history_lstm32 = model_lstm32.fit_generator(train_gen,
steps_per_epoch=steps_per_epoch_cnt,
epochs=50,
validation_data=val_gen,
validation_steps=val_steps_cnt,
callbacks=callbacks_list_lstm32, verbose=2) Epoch 1/50
20/20 [==============================] - 1s 38ms/step - loss: 0.1862
Epoch 00001: val_loss improved from inf to 0.18618, saving model to clark_best_lstm32.hdf5
- 18s - loss: 0.4808 - val_loss: 0.1862
Epoch 2/50
20/20 [==============================] - 1s 33ms/step - loss: 0.1496
Epoch 00002: val_loss improved from 0.18618 to 0.14965, saving model to clark_best_lstm32.hdf5
- 17s - loss: 0.3122 - val_loss: 0.1496
Epoch 3/50
20/20 [==============================] - 1s 35ms/step - loss: 0.1462
Epoch 00003: val_loss improved from 0.14965 to 0.14625, saving model to clark_best_lstm32.hdf5
- 18s - loss: 0.2731 - val_loss: 0.1462
Epoch 4/50
20/20 [==============================] - 1s 30ms/step - loss: 0.1438
Epoch 00004: val_loss improved from 0.14625 to 0.14383, saving model to clark_best_lstm32.hdf5
- 17s - loss: 0.2481 - val_loss: 0.1438
Epoch 5/50
20/20 [==============================] - 1s 31ms/step - loss: 0.1364
Epoch 00005: val_loss improved from 0.14383 to 0.13638, saving model to clark_best_lstm32.hdf5
- 17s - loss: 0.2247 - val_loss: 0.1364
Epoch 6/50
20/20 [==============================] - 1s 33ms/step - loss: 0.1361
Epoch 00006: val_loss improved from 0.13638 to 0.13614, saving model to clark_best_lstm32.hdf5
- 17s - loss: 0.2101 - val_loss: 0.1361
Epoch 7/50
20/20 [==============================] - 1s 46ms/step - loss: 0.1266
Epoch 00007: val_loss improved from 0.13614 to 0.12662, saving model to clark_best_lstm32.hdf5
- 19s - loss: 0.1899 - val_loss: 0.1266
Epoch 8/50
20/20 [==============================] - 1s 31ms/step - loss: 0.1360
Epoch 00008: val_loss did not improve from 0.12662
- 17s - loss: 0.1716 - val_loss: 0.1360
Epoch 9/50
20/20 [==============================] - 1s 36ms/step - loss: 0.1264
Epoch 00009: val_loss improved from 0.12662 to 0.12641, saving model to clark_best_lstm32.hdf5
- 17s - loss: 0.1583 - val_loss: 0.1264
Epoch 10/50
20/20 [==============================] - 1s 35ms/step - loss: 0.1375
Epoch 00010: val_loss did not improve from 0.12641
- 16s - loss: 0.1496 - val_loss: 0.1375
Epoch 11/50
20/20 [==============================] - 1s 33ms/step - loss: 0.1290
Epoch 00011: val_loss did not improve from 0.12641
- 17s - loss: 0.1506 - val_loss: 0.1290
Epoch 12/50
20/20 [==============================] - 1s 31ms/step - loss: 0.1341
Epoch 00012: val_loss did not improve from 0.12641
- 17s - loss: 0.1457 - val_loss: 0.1341
Epoch 13/50
20/20 [==============================] - 1s 54ms/step - loss: 0.1269
Epoch 00013: val_loss did not improve from 0.12641
- 19s - loss: 0.1442 - val_loss: 0.1269
Epoch 14/50
20/20 [==============================] - 1s 31ms/step - loss: 0.1369
Epoch 00014: val_loss did not improve from 0.12641
- 19s - loss: 0.1391 - val_loss: 0.1369
Epoch 15/50
20/20 [==============================] - 1s 34ms/step - loss: 0.1328
Epoch 00015: val_loss did not improve from 0.12641
- 18s - loss: 0.1361 - val_loss: 0.1328
Epoch 00015: early stopping
loss_lstm32 = history_lstm32.history['loss']
val_loss_lstm32 = history_lstm32.history['val_loss']
epochs = range(1, len(loss_lstm32) + 1)
plt.figure()
plt.plot(epochs, loss_lstm32, 'bo', label='Training loss')
plt.plot(epochs, val_loss_lstm32, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
print('Model Error:', f'{((min(val_loss_lstm32) * train_mw_std)/plant_capacity):0.2%}')Model Error: 2.77%
lstm32 = ((min(val_loss_lstm32) * train_mw_std)/plant_capacity) * 100filepath_lstm6432="clark_best_lstm6432.hdf5"
cp_lstm6432 = ModelCheckpoint(filepath_lstm6432, monitor='val_loss', verbose=2, save_best_only=True, mode='min')
es_lstm6432 = EarlyStopping(monitor='val_loss', mode='min', verbose=2, patience=10, min_delta=.01)
callbacks_list_lstm6432 = [cp_lstm6432, es_lstm6432]
# fix random seed for reproducibility
seed = 1337
np.random.seed(seed)
model_lstm6432 = Sequential()
model_lstm6432.add(layers.LSTM(64,
dropout=0.2,
recurrent_dropout=0.2,
return_sequences=True,
input_shape=(None, float_data.shape[-1])))
model_lstm6432.add(layers.LSTM(32,
dropout=0.2,
recurrent_dropout=0.2))
model_lstm6432.add(layers.Dense(32, activation='relu'))
model_lstm6432.add(layers.Dense(1))
model_lstm6432.compile(optimizer=RMSprop(), loss='mae')
history_lstm6432 = model_lstm6432.fit_generator(train_gen,
steps_per_epoch=steps_per_epoch_cnt,
epochs=50,
validation_data=val_gen,
validation_steps=val_steps_cnt,
callbacks=callbacks_list_lstm6432, verbose=2)Epoch 1/50
20/20 [==============================] - 2s 84ms/step - loss: 0.1595
Epoch 00001: val_loss improved from inf to 0.15946, saving model to clark_best_lstm6432.hdf5
- 46s - loss: 0.4159 - val_loss: 0.1595
Epoch 2/50
20/20 [==============================] - 1s 69ms/step - loss: 0.1199
Epoch 00002: val_loss improved from 0.15946 to 0.11991, saving model to clark_best_lstm6432.hdf5
- 42s - loss: 0.2417 - val_loss: 0.1199
Epoch 3/50
20/20 [==============================] - 1s 66ms/step - loss: 0.1290
Epoch 00003: val_loss did not improve from 0.11991
- 40s - loss: 0.1874 - val_loss: 0.1290
Epoch 4/50
20/20 [==============================] - 1s 67ms/step - loss: 0.1210
Epoch 00004: val_loss did not improve from 0.11991
- 40s - loss: 0.1660 - val_loss: 0.1210
Epoch 5/50
20/20 [==============================] - 2s 77ms/step - loss: 0.1203
Epoch 00005: val_loss did not improve from 0.11991
- 41s - loss: 0.1551 - val_loss: 0.1203
Epoch 6/50
20/20 [==============================] - 2s 83ms/step - loss: 0.1340
Epoch 00006: val_loss did not improve from 0.11991
- 41s - loss: 0.1528 - val_loss: 0.1340
Epoch 7/50
20/20 [==============================] - 1s 66ms/step - loss: 0.1215
Epoch 00007: val_loss did not improve from 0.11991
- 39s - loss: 0.1419 - val_loss: 0.1215
Epoch 8/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1299
Epoch 00008: val_loss did not improve from 0.11991
- 38s - loss: 0.1433 - val_loss: 0.1299
Epoch 9/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1234
Epoch 00009: val_loss did not improve from 0.11991
- 38s - loss: 0.1355 - val_loss: 0.1234
Epoch 10/50
20/20 [==============================] - 1s 69ms/step - loss: 0.1421
Epoch 00010: val_loss did not improve from 0.11991
- 38s - loss: 0.1325 - val_loss: 0.1421
Epoch 11/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1251
Epoch 00011: val_loss did not improve from 0.11991
- 39s - loss: 0.1322 - val_loss: 0.1251
Epoch 12/50
20/20 [==============================] - 1s 72ms/step - loss: 0.1347
Epoch 00012: val_loss did not improve from 0.11991
- 40s - loss: 0.1292 - val_loss: 0.1347
Epoch 00012: early stopping
loss_lstm6432 = history_lstm6432.history['loss']
val_loss_lstm6432 = history_lstm6432.history['val_loss']
epochs = range(1, len(loss_lstm6432) + 1)
plt.figure()
plt.plot(epochs, loss_lstm6432, 'bo', label='Training loss')
plt.plot(epochs, val_loss_lstm6432, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
print('Model Error:', f'{((min(val_loss_lstm6432) * train_mw_std)/plant_capacity):0.2%}')Model Error: 2.63%
lstm6432 = ((min(val_loss_lstm6432) * train_mw_std)/plant_capacity) * 100filepath_lstm3264 ="clark_best_lstm3264.hdf5"
cp_lstm3264 = ModelCheckpoint(filepath_lstm3264, monitor='val_loss', verbose=2, save_best_only=True, mode='min')
es_lstm3264 = EarlyStopping(monitor='val_loss', mode='min', verbose=2, patience=10, min_delta=.01)
callbacks_list_lstm3264 = [cp_lstm3264, es_lstm3264]
# fix random seed for reproducibility
seed = 1337
np.random.seed(seed)
model_lstm3264 = Sequential()
model_lstm3264.add(layers.LSTM(64,
dropout=0.2,
recurrent_dropout=0.2,
return_sequences=True,
input_shape=(None, float_data.shape[-1])))
model_lstm3264.add(layers.LSTM(32,
dropout=0.2,
recurrent_dropout=0.2))
model_lstm3264.add(layers.Dense(64, activation='relu'))
model_lstm3264.add(layers.Dense(1))
model_lstm3264.compile(optimizer=RMSprop(), loss='mae')
history_lstm3264 = model_lstm3264.fit_generator(train_gen,
steps_per_epoch=steps_per_epoch_cnt,
epochs=50,
validation_data=val_gen,
validation_steps=val_steps_cnt,
callbacks=callbacks_list_lstm3264, verbose=2)Epoch 1/50
20/20 [==============================] - 2s 86ms/step - loss: 0.1717
Epoch 00001: val_loss improved from inf to 0.17167, saving model to clark_best_lstm3264.hdf5
- 50s - loss: 0.3827 - val_loss: 0.1717
Epoch 2/50
20/20 [==============================] - 1s 71ms/step - loss: 0.1447
Epoch 00002: val_loss improved from 0.17167 to 0.14468, saving model to clark_best_lstm3264.hdf5
- 38s - loss: 0.2317 - val_loss: 0.1447
Epoch 3/50
20/20 [==============================] - 1s 64ms/step - loss: 0.1177
Epoch 00003: val_loss improved from 0.14468 to 0.11771, saving model to clark_best_lstm3264.hdf5
- 39s - loss: 0.1797 - val_loss: 0.1177
Epoch 4/50
20/20 [==============================] - 1s 64ms/step - loss: 0.1282
Epoch 00004: val_loss did not improve from 0.11771
- 37s - loss: 0.1620 - val_loss: 0.1282
Epoch 5/50
20/20 [==============================] - 2s 90ms/step - loss: 0.1210
Epoch 00005: val_loss did not improve from 0.11771
- 42s - loss: 0.1546 - val_loss: 0.1210
Epoch 6/50
20/20 [==============================] - 1s 66ms/step - loss: 0.1249
Epoch 00006: val_loss did not improve from 0.11771
- 49s - loss: 0.1525 - val_loss: 0.1249
Epoch 7/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1245
Epoch 00007: val_loss did not improve from 0.11771
- 36s - loss: 0.1434 - val_loss: 0.1245
Epoch 8/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1350
Epoch 00008: val_loss did not improve from 0.11771
- 37s - loss: 0.1449 - val_loss: 0.1350
Epoch 9/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1203
Epoch 00009: val_loss did not improve from 0.11771
- 37s - loss: 0.1356 - val_loss: 0.1203
Epoch 10/50
20/20 [==============================] - 1s 64ms/step - loss: 0.1250
Epoch 00010: val_loss did not improve from 0.11771
- 38s - loss: 0.1336 - val_loss: 0.1250
Epoch 11/50
20/20 [==============================] - 1s 64ms/step - loss: 0.1447
Epoch 00011: val_loss did not improve from 0.11771
- 38s - loss: 0.1332 - val_loss: 0.1447
Epoch 12/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1234
Epoch 00012: val_loss did not improve from 0.11771
- 37s - loss: 0.1302 - val_loss: 0.1234
Epoch 13/50
20/20 [==============================] - 1s 65ms/step - loss: 0.1325
Epoch 00013: val_loss did not improve from 0.11771
- 38s - loss: 0.1275 - val_loss: 0.1325
Epoch 00013: early stopping
loss_lstm3264 = history_lstm3264.history['loss']
val_loss_lstm3264 = history_lstm3264.history['val_loss']
epochs = range(1, len(loss_lstm3264) + 1)
plt.figure()
plt.plot(epochs, loss_lstm3264, 'bo', label='Training loss')
plt.plot(epochs, val_loss_lstm3264, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
print('Model Error:', f'{((min(val_loss_lstm3264) * train_mw_std)/plant_capacity):0.2%}')Model Error: 2.58%
lstm3264 = ((min(val_loss_lstm3264) * train_mw_std)/plant_capacity) * 100names = ['Industry Agnostic Naive Method',
'Industry Standard Naive Method',
'LSTM with 64 nodes',
'LSTM with 32 nodes',
'LSTM+LSTM with 64 nodes and 32 nodes',
'LSTM+LSTM with 32 nodes and 64 nodes']
results = [benchmark1,
benchmark2,
lstm64,
lstm32,
lstm6432,
lstm3264]results = pd.DataFrame(zip(names,results), columns=['Model', 'Error in Percentage'])results['Error in Percentage'] = round(results['Error in Percentage'],2)results['Improvement'] = round(1-(results['Error in Percentage']/benchmark2),4)*100results| Model | Error in Percentage | Improvement | |
|---|---|---|---|
| 0 | Industry Agnostic Naive Method | 5.84 | 53.21 |
| 1 | Industry Standard Naive Method | 12.48 | 0.00 |
| 2 | LSTM with 64 nodes | 2.82 | 77.40 |
| 3 | LSTM with 32 nodes | 2.77 | 77.80 |
| 4 | LSTM+LSTM with 64 nodes and 32 nodes | 2.63 | 78.93 |
| 5 | LSTM+LSTM with 32 nodes and 64 nodes | 2.58 | 79.33 |